﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Text;
using System.Security.Cryptography;
using System.Configuration;
using System.Collections.Generic;
using Citi.Helpers;
using Citi.SecurityHelper;

namespace Encrypt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            cboType.Items.Add(Citi.SecurityHelper.LoginType.ActiveDirectory.GetDescription());
            cboType.Items.Add(Citi.SecurityHelper.LoginType.Sso.GetDescription());
            cboType.Items.Add(Citi.SecurityHelper.LoginType.SsoSit.GetDescription());
            cboType.Items.Add(Citi.SecurityHelper.LoginType.SsoUat.GetDescription());
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRetypePassword.Text) || string.IsNullOrWhiteSpace(txtSoeid.Text))
            {
                MessageBox.Show("No field must be null", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtPassword.Text != txtRetypePassword.Text)
            {
                MessageBox.Show("Passwords are different", "Wrong password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            CitiPasswordFile.WriteFile(txtSoeid.Text, txtPassword.Text, (LoginType)cboType.SelectedIndex);

            MessageBox.Show("File successfully generated");
            txtPassword.Text = string.Empty;
            txtSoeid.Text = string.Empty;
            txtRetypePassword.Text = string.Empty;
            cboType.SelectedIndex = 0;
            txtSoeid.Focus();
        }

        private void encryptTextToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            new EncryptText().Show();
            Hide();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cboType.SelectedIndex = 0;
        }
    }
}
